#!/usr/bin/php -q
<?
require('../include/dblogin.inc.php');

mysql_connect(DATA_HOST, DATA_USER, DATA_PASS);
mysql_select_dB(DATA_BASE);

// Create an array representing the database structure.
$oDatabase = array();
$oQuery = mysql_query("SHOW TABLES");
while (list($sTablename) = mysql_fetch_row($oQuery)) {
	$oDatabase[$sTablename] = array();
	$oTableQuery = mysql_query("SHOW COLUMNS FROM $sTablename");
	while ($oRow = mysql_fetch_assoc($oTableQuery)) {
		$oDatabase[$sTablename][$oRow['Field']] = array(
			'type' => $oRow['Type'],
			'null' => ($oRow['Null'] == 'YES'),
			'primary_key' => ($oRow['Key'] == 'PRI'),
			'default' => $oRow['Default'],
			'extra' => $oRow['Extra']
		);
	}
}

// Create a PHP-usable file out of the whole thing.
print "<?\n";
print "\$oDatabase = array(\n";
foreach ($oDatabase as $sTablename => $oFields) {
	print "\t'$sTablename' => array(\n";
	foreach ($oFields as $sFieldname => $oParams) {
		print "\t\t'$sFieldname' => array(\n";
		foreach ($oParams as $sKey => $mValue) {
			print "\t\t\t'$sKey' => '".addslashes($mValue)."',\n";
		}
		print "\t\t),\n";
	}
	print "\t),\n";
}
print ");\n";
print "?>\n";

?>
